import modules from './modules'
import Vue from 'vue'
import Router from '@/plugin/uni-simple-router/index.js'
import {USER_TOKEN} from '@/common/util/constants.js'

Vue.use(Router)
//初始化
const router = new Router({
	mode: 'hash',
	encodeURI:true,  
    routes: [...modules]//路由表
});

//白名单(无需登录就能访问)
const whiteList = [
	'/pages/start-page/start-page',
	'/pages/login/login',
	'/pages/register/register',
	'/pages/singles/service-agreement',
	'/pages/singles/private-agreement',
	// '/pages/zxyp/list',
	
	
] 
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	let token=uni.getStorageSync(USER_TOKEN);
	//console.log('router index.js 1')
	if(token){
		//console.log('router index.js 2')
		 next()
	}else{
		//console.log('router index.js 3')
		if (whiteList.indexOf(to.path) !== -1) {
		  //console.log('router index.js 3-1')
		  next()
		}else{
			//console.log('router index.js 3-2')
		  next({ path: '/pages/login/login'})
		}
	} 
})
// 全局路由后置守卫
router.afterEach((to, from) => {
	//console.log("afterEach")
})
export default router;